import Vue from 'vue'
import Router from 'vue-router'
import login from '../components/mobile/login/login.vue'
import home from '../components/mobile/home/home.vue'
import mine from '../components/mobile/mine/mine.vue'
import infoList from '../components/mobile/infoList/infoList.vue'
import petLogs from '../components/mobile/mine/petLogs.vue'
import myPet from '../components/mobile/mine/myPet.vue'
import addPet from '../components/mobile/mine/addPet.vue'
import petLoclk from '../components/mobile/mine/petLoclk'
import communtiy from '../components/mobile/community/communtiy'
import communtiyInfo from '../components/mobile/community/communtiyInfo'
import addCommuntiy from '../components/mobile/community/addCommuntiy'
import questionsPanel from '../components/mobile/question/questionsPanel'
import regist from '../components/mobile/login/regist'
import medical from '../components/mobile/medical/medical1'
const questDetail = () =>
    import ("../components/mobile/question/questionDetail")
Vue.use(Router)

const router = new Router({
    routes: [{
            path: '/',
            redirect: '/home'
        },
        {
            path: '/home',
            name: 'home',
            component: home,
            meta: {
                keepAlive: true
            }
        },
        {
            path: '/mine',
            name: 'mine',
            component: mine,
            meta: {
                keepAlive: true
            },
            children: [

            ]
        },
        {
            path: '/infoList',
            name: 'infoList',
            component: infoList,
            meta: {
                keepAlive: true
            }
        },
        {
            path: '/petLogs',
            name: 'petLogs',
            component: petLogs,
            meta: {
                keepAlive: true
            }
        },
        {
            path: '/myPet',
            name: 'myPet',
            component: myPet,
            meta: {
                keepAlive: true
            }
        },
        {
            path: '/addPet',
            name: 'addPet',
            component: addPet
        },
        {
            path: '/petLoclk',
            name: 'petLoclk',
            component: petLoclk,
            meta: {
                keepAlive: true
            }
        },
        {
            path: '/login',
            component: login,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/communtiy',
            name: 'communtiy',
            component: communtiy,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/communtiyInfo',
            name: 'communtiyInfo',
            component: communtiyInfo,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/addCommuntiy',
            name: 'addCommuntiy',
            component: addCommuntiy,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/questionsPanel',
            component: questionsPanel,
            meta: {
                keepAlive: false
            },
            // components:{
            //     question_div:questionsPanel
            // }
        },
        {
            path: '/questionDetail/:id',
            component: questDetail,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/regist',
            component: regist,
            meta: {
                keepAlive: false
            }
        },
        {
            path: '/medical',
            component: medical,
            meta: {
                keepAlive: false
            }

        }
    ]
});
router.beforeEach((to, from, next) => {
    if (to.path === '/login' || to.path === '/regist') {
        localStorage.removeItem("petToken")
        next();
    } else {
        let token = localStorage.getItem("petToken");
        if (token === null || token === undefined) {
            next('/login');
        } else {
            next()
        }
    }
});

export default router;